﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:advadev.Windows.CustomWindows">

    <Style TargetType="{x:Type local:CustomWindow}">
        <Setter Property="AllowsTransparency" Value="True" />
        <Setter Property="Background" Value="White" />
        <Setter Property="BorderBrush" Value="#999999" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="WindowStyle" Value="None" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:CustomWindow}">
                    <AdornerDecorator>
                        <Grid>
                            <Border Name="outerBorder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="30" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>
                                    <Grid Name="PART_DragMoveArea" Grid.Row="0" Background="{TemplateBinding BorderBrush}">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="auto" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="auto" />
                                        </Grid.ColumnDefinitions>
                                        <Image Grid.Column="0" Source="{TemplateBinding Icon}" Width="30" />
                                        <TextBlock Grid.Column="1" Text="{TemplateBinding Title}" Foreground="White" Margin="5,0,5,0" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" />
                                        <StackPanel Grid.Column="2" Orientation="Horizontal">
                                            <StackPanel.Resources>
                                                <Style TargetType="{x:Type Button}">
                                                    <Setter Property="Height" Value="30" />
                                                    <Setter Property="Width" Value="30" />
                                                </Style>
                                            </StackPanel.Resources>
                                            <Button Content="M" Command="{x:Static local:CustomWindow.MinimizeCommand}" />
                                            <Button Content="R" Command="{x:Static local:CustomWindow.SwapWindowStateCommand}" />
                                            <Button Content="C" Command="{x:Static local:CustomWindow.CloseCommand}" />
                                        </StackPanel>
                                    </Grid>
                                    <Grid Grid.Row="1">
                                        <ContentPresenter />
                                    </Grid>
                                </Grid>
                            </Border>
                            <Grid>
                                <Grid.Resources>
                                    <Style TargetType="{x:Type Thumb}">
                                        <Setter Property="Background" Value="Transparent" />
                                        <Setter Property="BorderBrush" Value="Transparent" />
                                        <Setter Property="BorderThickness" Value="3" />
                                        <Setter Property="Visibility" Value="Visible" />
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=ResizeMode}" Value="NoResize">
                                                <Setter Property="Visibility" Value="Collapsed" />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=ResizeMode}" Value="CanMinimize">
                                                <Setter Property="Visibility" Value="Collapsed" />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=WindowState}" Value="Maximized">
                                                <Setter Property="Visibility" Value="Collapsed" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Grid.Resources>
                                <Thumb Name="PART_LeftResizeArea" HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="0,6,0,6" Width="6" Cursor="SizeWE" />
                                <Thumb Name="PART_LeftTopResizeArea" HorizontalAlignment="Left" VerticalAlignment="Top" Height="6" Width="6" Cursor="SizeNWSE" />
                                <Thumb Name="PART_TopResizeArea" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="6,0,6,0" Height="6" Cursor="SizeNS" />
                                <Thumb Name="PART_RightTopResizeArea" HorizontalAlignment="Right" VerticalAlignment="Top" Height="6" Width="6" Cursor="SizeNESW" />
                                <Thumb Name="PART_RightResizeArea" HorizontalAlignment="Right" VerticalAlignment="Stretch" Margin="0,6,0,6" Width="6" Cursor="SizeWE" />
                                <Thumb Name="PART_RightBottomResizeArea" HorizontalAlignment="Right" VerticalAlignment="Bottom" Height="6" Width="6" Cursor="SizeNWSE" />
                                <Thumb Name="PART_BottomResizeArea" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="6,0,6,0" Height="6" Cursor="SizeNS" />
                                <Thumb Name="PART_LeftBottomResizeArea" HorizontalAlignment="Left" VerticalAlignment="Bottom" Height="6" Width="6" Cursor="SizeNESW" />
                            </Grid>
                        </Grid>
                    </AdornerDecorator>
                    <ControlTemplate.Triggers>
                        <Trigger Property="WindowState" Value="Maximized">
                            <Setter TargetName="outerBorder" Property="BorderThickness" Value="0" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
